<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controlleradmin');

class LinkControllerLinks extends JControllerAdmin
{

    public function getModel ($name = 'Link', $prefix = 'LinkModel')
    {
        $model = parent::getModel($name, $prefix, array(
                'ignore_request' => true
        ));
        return $model;
    }

    function ajax_request_category ()
    {
        $app = JFactory::getApplication();
        $id = $app->input->get('id');
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select("title,id");
        $query->from("#__link_rss");
        $query->where("published = 1");
        $query->where("category = " . $db->quote($id));
        $db->setQuery($query);

        $rows = $db->loadObjectList();
        $str = '';
        $str .= "<option value=''>Select category</option>";
        if ($rows)
        {
            foreach ($rows as $row)
            {
                $str .= "<option value='{$row->id}'>{$row->title}</option>";
            }
        }
        echo ($str);
        exit();
    }

    function ajax_request_link ()
    {
        set_time_limit(10000);
        $app = JFactory::getApplication();
        $id = $app->input->get('id');
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select("*");
        $query->from("#__link_rss");
        $query->where("id = " . $db->quote($id));
        $db->setQuery($query);
        $row = $db->loadObject();

        $categoryArray = LinkHelper::_getList();
        $option = "<option value=''>Select category</option>";
        $options[] = 'Select category';
        if ($categoryArray)
        {
            foreach ($categoryArray as $category)
            {
                $option .= "<option value='{$category->id}'>{$category->title}</option>";
                $options[$category->id] = $category->title;
            }
        }
        $linkArray = null;
        if ($row && in_array($row->category,
                array(
                        1,
                        2,
                        3,
                        4,
                        5,
                        9,
                        10,
                )))
        {
            // $linkArray = simple_rss_dom::rss_list ( $row->link );
            $rss = new rss_php();
            $rss->load($row->link);
            $linkArray = $rss->getItems();
        }
        // get
        if ($row && $row->category == 6)
        {
            $linkArray = $this->get_link_genk_vn($row->link);
        }
        if ($row && $row->category == 7)
        {
            $linkArray = $this->get_link_vietnamplus($row->link);
        }
        if ($row && $row->category == 8)
        {
            $linkArray = $this->get_link_infonet($row->link);
        }
        // JHTML::_('select.genericlist', $options,'hocky', 'class="inputbox"
        // onchange="this.form.submit();"','value','text',$hocky)
        $str = null;
        $str .= "<tr>
					<td>#</td>
					<td width='400'><strong>title</strong></td>
					<td><strong>nguoivietodessa</strong></td>
				</tr>";
        if ($linkArray)
        {
            foreach ($linkArray as $link)
            {
                if ($cat = $this->check_exist_article(LinkHelper::strip_link($link['title'])))
                {
                    $str .= "<tr>
					   <td></td>
					   <td width='400'>{$link['title']}</td>
					   <td>" . JHTML::_('select.genericlist', $options, '', 'class="inputbox"', 'value', 'text', $cat) . "</td>
				   </tr>";
                }
                else
                {
                    $str .= "<tr>
					       <td><input type='checkbox' name='link[]' value='{$link['link']}'></td>
					       <td width='400'>{$link['title']}</td>
							<td><select class='category' name='category[]'>'.$option.'</select></td>
					</tr>";
                }
            }
        }
        echo $str;
        exit();
    }

    function get_link_genk_vn ($link)
    {
        $html = file_get_contents($link);
        $html = str_get_html($html);
        $linkArray = array();
        foreach ($html->find('div.list-news div.list-news-status h2 a') as $element)
        {
            $title = $element->plaintext;
            $link = $element->href;
            $linkArray[] = array(
                    'link' => 'http://genk.vn' . $link,
                    'title' => $title
            );
        }
        return $linkArray;
    }

    function get_link_vietnamplus ($link)
    {
        $html = file_get_contents($link);
        $html = str_get_html($html);
        $linkArray = array();
        foreach ($html->find('.story-listing .story .thumbnail a') as $element)
        {
            $link = $element->href;
            $title = $element->children(0)->alt;
            $linkArray[] = array(
                    'link' => 'http://www.vietnamplus.vn' . $link,
                    'title' => $title
            );
        }
        return $linkArray;
    }

    function get_link_infonet ($link)
    {
        $html = file_get_contents($link);
        $html = str_get_html($html);
        $linkArray = array();
        foreach ($html->find('.story .thumb a') as $element)
        {
            $link = $element->href;
            $title = $element->children(0)->alt;
            $linkArray[] = array(
                    'link' => 'http://infonet.vn' . $link,
                    'title' => $title
            );
        }
        
       
        
        return $linkArray;
    }

    function getCurldata ($url)
    {
        $cc = new cURL();
        $data = $cc->get($url);
        return $data;
    }

    function check_exist_article ($title)
    {
        $app = JFactory::getApplication();
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select("catid");
        $query->from("#__k2_items");
        $query->where("alias like " . $db->quote('%' . $title . '%'));

        $db->setQuery($query);
        $row = $db->loadResult();

        return ($row) ? $row : null;
    }

    function save_acticle ()
    {
        set_time_limit(10000);
        $app = JFactory::getApplication();
        $link = $app->input->get('link', array(), 'array');
        $cat = $app->input->get('category', array(), 'array');
        $link = array_filter($link);
        $cat = array_filter($cat);
        $category = array();
        foreach ($cat as $key => $val)
        {
            $category[] = $val;
        }
        $type = $app->input->get('type');
        switch ($type)
        {

            case 1:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_vnexpress($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }
                            $errors[] = "Can't get article : {$val}";
                        }
                    }
                }

                break;
            case 2:

                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_thanhnien($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                           
                        }
                    }
                }

                break;
            case 3:

                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_tienphong($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 4:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_laodong($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 5:
                if (count($link) && count($category))
                {

                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_dantri($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 6:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_genk($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 7:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_vietnamplus($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 8:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_infonet($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
            case 9:
                if (count($link) && count($category))
                {
                    foreach ($link as $key => $val)
                    {
                        if ($val && $category[$key])
                        {
                            $cc = new cURL();
                            $html = $cc->get(trim($val));
                            if ($html) {
	                            $array = $this->process_kinhdoanh_vnexpress($html);
	                            $array['catid'] = $category[$key];
	                            if (! $this->check_exist_article($array['alias']))
	                            {
	                                $this->insert_db($array);
	                            }
                            }else {
                            	$errors[] = "Can't get article : {$val}";
                            }
                            
                        }
                    }
                }
                break;
                case 10:
                    if (count($link) && count($category))
                    {
                        foreach ($link as $key => $val)
                        {
                            if ($val && $category[$key])
                            {
                                $cc = new cURL();
                                $html = $cc->get(trim($val));
                                if ($html) {
                                	$array = $this->process_thethao_vnexpress($html);
                                	$array['catid'] = $category[$key];
                                	if (! $this->check_exist_article($array['alias']))
                                	{
                                		$this->insert_db($array);
                                	}
                                }else {
                                	$errors[] = "Can't get article : {$val}";
                                }
                                
                            }
                        }
                    }
                    break;

        }

        $this->setRedirect('index.php?option=com_link&view=detail',implode("<br />", $pieces));
    }

    function insert_db ($content)
    {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        // Insert columns.
        $columns = array(
                'title',
                'alias',
                'catid',
                'published',
                'introtext',
                'fulltext',
                'video',
                'gallery',
                'extra_fields',
                'extra_fields_search',
                'created',
                'created_by',
                'created_by_alias',
                'checked_out',
                'checked_out_time',
                'modified',
                'modified_by',
                'publish_up',
                'publish_down',
                'trash',
                'access',
                'ordering',
                'featured',
                'featured_ordering',
                'image_caption',
                'image_credits',
                'video_caption',
                'video_credits',
                'hits',
                'params',
                'metadesc',
                'metadata',
                'metakey',
                'plugins',
                'language'
        );
        $config = JFactory::getConfig();
        $offset = $config->get('offset');
        
        //get the current system date and time and add the offset
        $date =& JFactory::getDate('',$offset);
        
        //Convert to mysql format
       
        
        $values = array(
                // title
                $db->quote(trim($content['title'])),
                // alias
                $db->quote(trim($content['alias'])),
                // catid
                $db->quote($content['catid']),
                // published
                $db->quote(1),
                // introtext
                $db->quote($content['introtext']),
                // fulltext
                $db->quote($content['fulltext']),
                // video
                $db->quote(''),
                // gallery
                $db->quote(''),
                // extra_fields
                $db->quote('[]'),
                // extra_fields_search
                $db->quote(''),
                // created
                $db->quote($date),
                // created_by
                $db->quote(JFactory::getUser()->id),
                // created_by_alias
                $db->quote(''),
                // checked_out
                $db->quote('0'),
                // checked_out_time
                $db->quote('0000-00-00 00:00:00'),
                // modified
                $db->quote('0000-00-00 00:00:00'),
                // modified_by
                $db->quote(''),
                // publish_up
                $db->quote($date),
                // publish_down
                $db->quote('0000-00-00 00:00:00'),
                // trash
                $db->quote('0'),
                // access
                $db->quote('1'),
                // ordering
                $db->quote(''),
                // featured
                $db->quote('0'),
                // featured_ordering
                $db->quote('1'),
                // image_caption
                $db->quote(''),
                // image_credits
                $db->quote(''),
                // video_caption
                $db->quote(''),
                // video_credits
                $db->quote(''),
                // hits
                $db->quote(0),
                // params
                $db->quote(
                        '{"catItemTitle":"","catItemTitleLinked":"","catItemFeaturedNotice":"","catItemAuthor":"","catItemDateCreated":"","catItemRating":"","catItemImage":"","catItemIntroText":"","catItemExtraFields":"","catItemHits":"","catItemCategory":"","catItemTags":"","catItemAttachments":"","catItemAttachmentsCounter":"","catItemVideo":"","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"","catItemImageGallery":"","catItemDateModified":"","catItemReadMore":"","catItemCommentsAnchor":"","catItemK2Plugins":"","itemDateCreated":"","itemTitle":"","itemFeaturedNotice":"","itemAuthor":"","itemFontResizer":"","itemPrintButton":"","itemEmailButton":"","itemSocialButton":"","itemVideoAnchor":"","itemImageGalleryAnchor":"","itemCommentsAnchor":"","itemRating":"","itemImage":"","itemImgSize":"","itemImageMainCaption":"","itemImageMainCredits":"","itemIntroText":"","itemFullText":"","itemExtraFields":"","itemDateModified":"","itemHits":"","itemCategory":"","itemTags":"","itemAttachments":"","itemAttachmentsCounter":"","itemVideo":"","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"","itemVideoCaption":"","itemVideoCredits":"","itemImageGallery":"","itemNavigation":"","itemComments":"","itemTwitterButton":"","itemFacebookButton":"","itemGooglePlusOneButton":"","itemAuthorBlock":"","itemAuthorImage":"","itemAuthorDescription":"","itemAuthorURL":"","itemAuthorEmail":"","itemAuthorLatest":"","itemAuthorLatestLimit":"","itemRelated":"","itemRelatedLimit":"","itemRelatedTitle":"","itemRelatedCategory":"","itemRelatedImageSize":"","itemRelatedIntrotext":"","itemRelatedFulltext":"","itemRelatedAuthor":"","itemRelatedMedia":"","itemRelatedImageGallery":"","itemK2Plugins":""}'),
                // metadesc
                $db->quote(''),
                // metadata
                $db->quote('robots=
							 author='),
                // metakey
                $db->quote(''),
                // plugins
                $db->quote(''),
                // language
                $db->quote('*')
        );

        // Prepare the insert query.
        $query->insert($db->quoteName('#__k2_items'))
            ->columns($db->quoteName($columns))
            ->values(implode(',', $values));

        // Set the query using our newly populated query object and execute it.
        $db->setQuery($query);
        $db->query();
    }

    function process_vnexpress ($html)
    {
        $html = str_get_html($html);
        foreach ($html->find('div.content-center h1.Title') as $element)
        {
            $title = $element->plaintext;
        }
        foreach ($html->find('div.content-center h2.Lead') as $element)
        {
            $introtext = strip_tags($element);
        }

        foreach ($html->find('div.content-center .cxtLeft .fck_detail') as $element)
        {
            $fulltext = $element;
        }
        foreach ($fulltext->find('img') as $element)
        {
            if ($element->parent()->tag == 'td')
            {
                $element->parent()->class = 'image';
            }

            if ($element->parent()
                ->parent()
                ->parent()
                ->parent()->tag == 'table')
            {
                $element->parent()
                    ->parent()
                    ->parent()
                    ->parent()->class = 'Odessa-image';
            }
            foreach ($element->parent()
                ->parent()
                ->parent()
                ->parent()
                ->find('td') as $element)
            {

                if ($element->class == '')
                {
                    $element->class = 'caption';
                }
            }
        }

        $fulltext .= "<p>Theo Vnexpress </p>";

        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_thanhnien ($html)
    {
        $title = '';
        $fulltext = '';
        $introtext = '';
        $html = str_get_html($html);

        foreach ($html->find("#print-news h1.mainTitle") as $element)
        {
            $title = $element->plaintext;
        }
        foreach ($html->find('#print-news .article-ds  h2.ms-rteElement-H2') as $element)
        {
            $introtext = $element;
        }
        $introtext = strip_tags($introtext);

        foreach ($html->find('#print-news .article-ds') as $element)
        {
            $fulltext = $element;
        }

        foreach ($fulltext->find('img') as $img)
        {
            $src = $img->src;
            $img->src = 'http://www.thanhnien.com.vn' . $src;

            if ($img->parent()->tag == 'td')
            {
                $img->parent()->class = 'image';
            }
            // class="Odessa-image"
            if ($img->parent()->parent()->tag == 'table')
            {
                $img->parent()->parent()->class = 'Odessa-image';
            }
            foreach ($img->parent()
                ->parent()
                ->find('td') as $element)
            {
                $element->class = 'caption';
            }
        }

        foreach ($fulltext->find('h2.ms-rteElement-H2') as $k => $p)
        {
            $p->innertext = '';
        }
        foreach ($fulltext->find('p') as $k => $p)
        {
            if ($k == 0)
            {
                $p->innertext = '';
            }
        }
        $fulltext->find('p', $k)->innertext = '';

        foreach ($fulltext->find('a') as $a)
        {
            $text = $a->innertext;
            $a->outertext = $text;
        }
        foreach ($fulltext->find('table') as $talbe)
        {
            foreach ($talbe->find('td') as $td)
            {

                if ($td->find('img'))
                {
                    $td->class = 'image';
                }
                elseif ($td->class == '')
                {
                    $td->class = 'caption';
                }
            }
            $talbe->class = 'Odessa-image';
        }

        $fulltext .= "<p>Theo Thanhnien </p>";
        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_tienphong ($html)
    {
        $html = str_get_html($html);

        $title = '';
        $fulltext = '';
        $introtext = '';

        // get title
        // get introtext
        foreach ($html->find('.article-header h1') as $element)
        {
            $title = $element->plaintext;
        }
        foreach ($html->find('.article-photo') as $element)
        {
            $introtext .= $element;
        }

        foreach ($html->find('.article-contents  .summary') as $element)
        {
            $introtext .= $element;
        }

        $introtext = trim($introtext);

        // get funtext
        foreach ($html->find('#article-body') as $element)
        {
            $fulltext .= $element;
        }
        $fulltext = str_get_html($fulltext);
        foreach ($fulltext->find('img') as $img)
        {
            $src = $img->src;
            $img->src = 'http://www.tienphong.vn' . $src;
            $img->setAttribute('text-align', 'center');
            $img->parent()->class = 'center';
        }

        $fulltext .= "<p>Theo Tienphong </p>";
        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_laodong ($html)
    {
        $title = '';
        $fulltext = '';
        $introtext = '';
        // get title
        $html = str_get_html($html);
        foreach ($html->find('img') as $img)
        {
            $src = $img->src;
            $img->src = 'http://laodong.com.vn' . $src;
        }
        foreach ($html->find('.article-content .main-contents header') as $element)
        {
            $title = $element->plaintext;
        }
        foreach ($html->find('.article-content .main-contents') as $element)
        {
            $introtext = $element;
        }
        foreach ($introtext->find('.stories-box-horizontal') as $element)
        {
            $element->outertext = '';
        }
        foreach ($introtext->find('.meta') as $element)
        {
            $element->outertext = '';
        }
        foreach ($introtext->find('header') as $element)
        {
            $element->outertext = '';
        }
        $introtext = str_get_html($introtext);
        foreach ($introtext->find('div.article-body') as $element)
        {
            $element->outertext = '';
        }
        $introtext = strip_tags($introtext, '<a><img><b><strong>');

        foreach ($html->find('div.article-body') as $element)
        {
            $fulltext = $element;
        }

        foreach ($fulltext->find('table') as $talbe)
        {
            foreach ($talbe->find('td') as $td)
            {

                if ($td->find('img'))
                {
                    $td->class = 'image';
                }
                elseif ($td->class == '')
                {
                    $td->class = 'caption';
                }
            }
            $talbe->class = 'Odessa-image';
        }

        $fulltext .= "<p>Theo Laodong </p>";

        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_dantri ($html)
    {
        $title = '';
        $fulltext = '';
        $introtext = '';
        $html = str_get_html($html);
        foreach ($html->find('#ctl00_IDContent_ctl00_divContent h1.mt2') as $element)
        {
            $title = $element->plaintext;
        }
        foreach ($html->find('#ctl00_IDContent_ctl00_divContent h2.mt1') as $element)
        {
            $introtext = $element;
        }
        foreach ($introtext->find('a') as $element)
        {
            $element->outertext = '';
        }
        foreach ($html->find('#ctl00_IDContent_ctl00_divContent div.mt3') as $element)
        {
            $fulltext = $element;
        }
        foreach ($fulltext->find('.news-tag') as $element)
        {
            $element->outertext = '';
        }
        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_genk ($html)
    {
        $html = str_get_html($html);
        $title = '';
        $fulltext = '';
        $introtext = '';

        foreach ($html->find('.news-showtitle h1') as $element)
        {
            $title = $element->plaintext;
        }

        foreach ($html->find('.content  h2.init_content') as $element)
        {
            $introtext = $element;
        }

        foreach ($html->find('.content') as $element)
        {
            $fulltext = $element;
        }

        foreach ($fulltext->find('h2.init_content') as $element)
        {
            $element->outertext = '';
        }

        foreach ($fulltext->find('ul.relate-news') as $element)
        {
            $element->outertext = '';
        }

        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_vietnamplus ($html)
    {
        $html = str_get_html($html);
        $title = '';
        $fulltext = '';
        $introtext = '';

        foreach ($html->find('.article .article-header h1') as $element)
        {
            $title = $element->plaintext;
        }

        foreach ($html->find('.wrap-article  .article-contents') as $element)
        {
            $introtext = $element;
        }
        $alias = LinkHelper::strip_link($title);

        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }

    function process_infonet ($html)
    {
        $html = str_get_html($html);
        $title = '';
        $fulltext = '';
        $introtext = '';

        foreach ($html->find('#article-header h1.title') as $element)
        {
            $title = $element->plaintext;
        }

        foreach ($html->find('.article-contents   .summary') as $element)
        {
            $introtext = $element;
        }

        foreach ($html->find('.article-contents') as $element)
        {
            $fulltext = $element;
        }
        $fulltext = str_get_html($fulltext);
        foreach ($fulltext->find('.summary') as $element)
        {
            $element->outertext = '';
        }
        
        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }
    function process_kinhdoanh_vnexpress ($html)
    {
        $title = '';
        $fulltext = '';
        $introtext = '';
        $html = str_get_html($html);
        foreach ($html->find('.content_news .title_news h1') as $element)
        {
           $title = $element->plaintext;
        }

        foreach ($html->find('.content_news .short_intro ') as $element)
        {
            $introtext = $element;
        }

        foreach ($html->find('.content_news .fck_detail') as $element)
        {
            $fulltext = $element;
        }

        $alias = LinkHelper::strip_link($title);
        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );
    }
    function process_thethao_vnexpress($html){
        $title = '';
        $fulltext = '';
        $introtext = '';
        $html = str_get_html($html);

        foreach ($html->find('.content_news .title_news h1') as $element)
        {
           $title = $element->plaintext;
        }

        foreach ($html->find('.content_news .short_intro ') as $element)
        {
            $introtext = $element;
        }

        foreach ($html->find('.content_news .fck_detail') as $element)
        {
            $fulltext = $element;
        }

        $alias = LinkHelper::strip_link($title);

        return array(
                'title' => $title,
                'introtext' => $introtext,
                'fulltext' => $fulltext,
                'alias' => $alias
        );

    }
}


